package com.mingtu.guards.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.AllSignInRecordBean;

import java.util.List;

public class AllSignInRecordAdapter extends BaseQuickAdapter<AllSignInRecordBean.PageBean.ListBean, BaseViewHolder> {

    private Context context;

    public AllSignInRecordAdapter(Context context) {
        super(R.layout.item_all_sign_in_record);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, AllSignInRecordBean.PageBean.ListBean listBean) {
        String content = listBean.getContent();
        String clockTime = listBean.getClockTime();
        String userName = listBean.getUserName();
        String lnglat = listBean.getLnglat();
        List<AllSignInRecordBean.PageBean.ListBean.TaskClockAttachEntityListBean> entityList = listBean.getTaskClockAttachEntityList();

        if (!StringUtils.isEmpty(content)) {
            helper.setText(R.id.tv_title, content);
        }
        if (!StringUtils.isEmpty(clockTime)) {
            helper.setText(R.id.tv_time, clockTime);
        }
        if (!StringUtils.isEmpty(userName)) {
            helper.setText(R.id.tv_name, "姓名：" + userName);
        }

        if (!StringUtils.isEmpty(lnglat)) {
            if (lnglat.indexOf(",") != -1) {
                String[] array = lnglat.split(",");

                double lng = Double.parseDouble(array[0]);
                double lat = Double.parseDouble(array[1]);
                String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
                String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);
                helper.setText(R.id.tv_location, "经纬度：" + myLng + "," + myLat);
            }
        }

        if (entityList.size() > 0) {
            AllSignInRecordBean.PageBean.ListBean.TaskClockAttachEntityListBean entityListBean = entityList.get(0);
            String url = entityListBean.getUrl();
            Glide.with(context)
                    .load(url)
                    .apply(BaseApplication.getRequestOptions())
                    .into((ImageView) helper.getView(R.id.iv_img));
        }
    }

}
